home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK1.toast / Development Kits (Disc 1) / AppleScript / Development Tools / Sample Code / Sample OSA Component / In MW C with Tester / MyOSAComponentRoutines.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  19.0 KB  |  715 lines  |  [TEXT/MMCC]

  1. /*
  2.  File MyOSAComponentRoutines.c
  3.  
  4.  
  5.  
  6.  Copyright © 1992-1993 Apple Computer, Inc. All rights reserved.}
  7.  
  8.  This is a sample program to implement the OSA interface. 
  9.  In this sample program, the source is the same as the internal compiled form. 
  10.  So compile and decompile just consists of copying and rename, and this is very 
  11.  unlike other OSA implementation. However, there is a lot of scripting language 
  12.  which just interprets the source and this sample program can be useful.
  13.  
  14.  Ported over to C 9/20/95
  15.  R.Silva
  16.  
  17.  
  18.  
  19. */
  20.  
  21. #ifdef THINK_C
  22. #define        applec
  23. #endif
  24.  
  25. //#include     "myHeaders.h"
  26.  
  27. #include    <Errors.h>
  28. #include    <TextEdit.h>
  29. #include    <Components.h>
  30. #include    <OSAComp.h>
  31.  
  32. #include    "MyOSAComponent.h"
  33. #include    "MyOSAComponentRoutines.h"
  34.  
  35.  
  36. //prototyping
  37. ComponentResult FindSlotAndPutIt(GlobalsHandle globals, AEDesc theDesc,long *slotID);                              
  38. long     FindScriptIDSlot(GlobalsHandle globals);
  39. void      NukeIt(AEDesc *theDesc);
  40. void     ClearErrorDesc(GlobalsHandle globals);
  41. OSErr     TextToStxt(AEDesc textDesc, AEDesc *result);
  42. ComponentResult TryDoScript(GlobalsHandle globals, AEDesc *scriptData, int  *num);
  43. ComponentResult ActualDoScript(GlobalsHandle globals, AEDesc *scriptData, AEDesc *result);
  44. int        myStrcmp( char * firstString, char * secString);
  45. OSErr     myStrcat( char * firstString, char * secString);
  46. int     myStrlen( char * theString); 
  47.                          
  48. /* ------------------------------------------------------------------------- */
  49. //  put a desc into a slot, if slotID starts as 0 find a new slot, 
  50. //  otherwise reuse the slot ID 
  51. //
  52. ComponentResult FindSlotAndPutIt(GlobalsHandle globals, AEDesc theDesc, long *slotID)
  53. {
  54.     OSErr err = noErr;
  55.     AEDesc  *oldDesc;
  56.     long    mySlot;
  57.          
  58.     mySlot = *slotID;
  59.     HLock((Handle)globals);
  60.     if( theDesc.dataHandle == nil){ 
  61.         mySlot = 0;
  62.         err = memFullErr;
  63.     }
  64.     else{
  65.         if( mySlot == 0 ){ 
  66.             mySlot = FindScriptIDSlot(globals); //find an empty slot
  67.         }
  68.         else{
  69.             //reuse an existing slot, we first dispose the old content
  70.             oldDesc =  &((*globals)->scriptIDSlot[mySlot]);
  71.             AEDisposeDesc(oldDesc);
  72.         }
  73.         if( slotID != 0 ) {
  74.             //keep the same handle
  75.             ((*globals)->scriptIDSlot[mySlot] ).dataHandle = theDesc.dataHandle;
  76.             ((*globals)->scriptIDSlot[mySlot] ).descriptorType = theDesc.descriptorType;
  77.         }
  78.         else{
  79.             err = memFullErr; //no slot available, treat it as memory error because
  80.                               //in a more realistic program we would expand the slots 
  81.             mySlot = 0;
  82.             //get rid of it since it wasnt used
  83.             AEDisposeDesc(&theDesc);
  84.         }
  85.     }
  86.     HUnlock((Handle)globals);
  87.     *slotID = mySlot;
  88.          
  89.     return err;
  90. }
  91. //search for a empty slot and return the slot ID, return 0 if none is available
  92. //start at the number 1 slot,  zero means  "get a new slot"
  93. //
  94. long FindScriptIDSlot(GlobalsHandle globals)
  95. {
  96.     int  i;
  97.  
  98.     for( i = 1; i<  MaxIDSlot ; i++) { 
  99.         if( ((*globals)->scriptIDSlot)[i].dataHandle == nil ) {
  100.         break;
  101.         }
  102.     }
  103.     if(i == MaxIDSlot) i = 0;
  104.     return i;
  105. }
  106. //
  107. //make a copy, strip the trailer and put it into a slot
  108. //
  109. pascal ComponentResult DoOSALoad(Handle myGlobals, AEDesc *scriptData,
  110.                        long  modeFlags, OSAID *resultingScriptID)
  111. {
  112.     ComponentResult err;
  113.     AEDesc  descCopy;
  114.     DescType  itsType;
  115.     GlobalsHandle globals; 
  116.  
  117.  
  118.     globals = (GlobalsHandle) myGlobals;
  119.         
  120.     err = errOSABadStorageType;
  121.     if ((*scriptData).descriptorType == kOSAGenericScriptingComponentSubtype) {  
  122.         if( OSAGetStorageType((*scriptData).dataHandle, &itsType) == noErr ) {  
  123.             if(  itsType == MySignature ) {  
  124.                 err = AEDuplicateDesc(scriptData, &descCopy);
  125.                 if( err == noErr) { err = OSARemoveStorageType(descCopy.dataHandle); }
  126.                 //internally we store as type 'SMPL'
  127.                 descCopy.descriptorType = MySignature;
  128.                 //we want a new OSAID 
  129.                 resultingScriptID = 0;  
  130.                 err = FindSlotAndPutIt(globals, descCopy, (long *) resultingScriptID);
  131.             }
  132.         }
  133.     }
  134.     return err;
  135. }
  136. //make a null descriptor
  137. void  NukeIt(AEDesc *theDesc)
  138.     theDesc->descriptorType = typeNull;
  139.     theDesc->dataHandle = nil;
  140. }
  141.  
  142. //make a copy of content in the slot and add trailer
  143. //
  144. pascal ComponentResult DoOSAStore(GlobalsHandle globals, OSAID scriptID,
  145.                         DescType desiredType,long  modeFlags,
  146.                         AEDesc  *resultingScriptData)
  147. {    
  148.     ComponentResult err;
  149.     
  150.     NukeIt(resultingScriptData);
  151.     if( (scriptID <= 0) || (scriptID > MaxIDSlot - 1) ) {
  152.         err = errOSAInvalidID;
  153.     }
  154.     else{
  155.         HLock((Handle)globals);
  156.         err = AEDuplicateDesc( &((*globals)->scriptIDSlot[scriptID]),resultingScriptData) ;
  157.         HUnlock((Handle)globals);
  158.         if( err != noErr ) { 
  159.             NukeIt(resultingScriptData); 
  160.         }
  161.         if( (*resultingScriptData).dataHandle == nil){
  162.             err = errOSAInvalidID;
  163.         }
  164.         else{ 
  165.             err = OSAAddStorageType( (*resultingScriptData).dataHandle, (*resultingScriptData).descriptorType);
  166.             if( err == noErr) { 
  167.                 (*resultingScriptData).descriptorType = kOSAGenericScriptingComponentSubtype;
  168.             }
  169.             else {
  170.                 AEDisposeDesc(resultingScriptData);
  171.                 NukeIt(resultingScriptData);
  172.             }
  173.         }
  174.     }
  175.     return err;
  176. }
  177. //fetch the content of the error descriptor
  178. //
  179. pascal ComponentResult DoOSAScriptError(GlobalsHandle globals, OSType selector,
  180.                               DescType desiredType, AEDesc *resultingErrorDescription)
  181. {
  182.     ComponentResult err;
  183.     long i;
  184.     AERecord aRec ;
  185.     AEDesc *myErrorDesc ;
  186.     int errNum;
  187.     
  188.     NukeIt(resultingErrorDescription);
  189.     if( selector == kOSAErrorNumber ) { 
  190.         HLock((Handle)globals);
  191.         errNum = (*globals)->errorNumber;
  192.         HUnlock((Handle)globals);
  193.         err = AECoercePtr(typeShortInteger, &errNum, sizeof(int), desiredType, resultingErrorDescription);
  194.     }
  195.     else if ( selector == kOSAErrorMessage) {
  196.         HLock((Handle)globals);
  197.         myErrorDesc = &((*globals)->errorDesc);
  198.         if( (desiredType == typeChar) || (desiredType == typeWildCard) ){ 
  199.             err = AEDuplicateDesc(myErrorDesc, resultingErrorDescription);
  200.         }
  201.         else if ( desiredType == 'STXT') { 
  202.             err = TextToStxt(*myErrorDesc, resultingErrorDescription);
  203.         }
  204.         else {
  205.             err = AECoerceDesc(myErrorDesc, desiredType, resultingErrorDescription);
  206.         }
  207.         HUnlock((Handle)globals);
  208.     }
  209.     else if( selector == kOSAErrorRange) {
  210.         //in this simple example, we make the error range to include everything
  211.         err = AECreateList(nil, 0, true, &aRec);
  212.         if( err == noErr) {
  213.             i = 0;
  214.             AEPutKeyPtr(&aRec, keyOSASourceStart, typeLongInteger, &i, sizeof(i));
  215.             i = 30000;
  216.             AEPutKeyPtr(&aRec, keyOSASourceEnd, typeLongInteger, &i, sizeof(i) );
  217.             if( desiredType == typeAERecord ) {
  218.                 err = AEDuplicateDesc(&aRec, resultingErrorDescription);
  219.             }
  220.             else {
  221.                 if( desiredType == typeWildCard ){  
  222.                     desiredType = typeOSAErrorRange; 
  223.                     err = AECoerceDesc(&aRec, desiredType, resultingErrorDescription);
  224.                 }
  225.             }
  226.             AEDisposeDesc(&aRec);
  227.         }
  228.     }
  229.     else{
  230.         err = errOSABadSelector;
  231.     }
  232.     return err;
  233. }
  234. //
  235. //dispose the descriptor in the slot I check whether the dataHandle is nil first  
  236. //
  237. pascal ComponentResult DoOSADispose(GlobalsHandle  globals,
  238.                           OSAID scriptID)
  239. {    
  240.     if( (scriptID > 0) && (scriptID < MaxIDSlot) ) { 
  241.         HLock((Handle)globals);
  242.         if(((*globals)->scriptIDSlot[scriptID]).dataHandle != nil ){
  243.             AEDisposeDesc(&((*globals)->scriptIDSlot[scriptID]));
  244.             ((*globals)->scriptIDSlot[scriptID]).dataHandle = nil;
  245.         }
  246.         HUnlock((Handle)globals);
  247.     }
  248.     return noErr;
  249. }
  250. //
  251. //since in this sample program, internal form is the same as source form
  252. //except for the descriptor type, we can just call CompileExecute 
  253. pascal ComponentResult DoOSAExecute(GlobalsHandle globals,  OSAID compiledScriptID,
  254.                           OSAID contextID, long  modeFlags, OSAID *resultingScriptValueID)
  255. {
  256.     AEDesc myDesc;
  257.     ComponentResult  err;
  258.  
  259.     *resultingScriptValueID = 0;
  260.     if( (compiledScriptID <= 0) || (compiledScriptID > MaxIDSlot - 1) )   
  261.         return errOSAInvalidID;
  262.     else{
  263.         HLock((Handle)globals);
  264.         err = AEDuplicateDesc(&((*globals)->scriptIDSlot[compiledScriptID]), &myDesc);
  265.         HUnlock((Handle)globals);
  266.         if(err == noErr){
  267.             err = DoOSACompileExecute(globals, &myDesc, 
  268.                               contextID, modeFlags, resultingScriptValueID);
  269.               AEDisposeDesc(&myDesc);
  270.         }
  271.     }
  272.     return err;
  273. }
  274. //
  275. //in this program, we have no special form for display so just coerce it
  276. //
  277. pascal ComponentResult DoOSADisplay(GlobalsHandle globals, OSAID  scriptValueID,
  278.                           DescType  desiredType, long modeFlags,
  279.                           AEDesc *resultingText)
  280. {
  281.     
  282.     return DoOSACoerceToDesc(globals, scriptValueID, desiredType, modeFlags, resultingText);
  283. }
  284. //
  285. //since internal form is same as source, just change the dataType and call TryDoScript, 
  286. //if it compiles then just store it
  287. pascal ComponentResult DoOSACompile(GlobalsHandle  globals, AEDesc  *sourceData,
  288.                           long modeFlags, OSAID *resultingCompiledScriptID)
  289. {
  290.     ComponentResult err;
  291.     AEDesc descCopy;
  292.     int  num;
  293.         
  294.     if( (*sourceData).descriptorType == typeChar) { 
  295.         (*sourceData).descriptorType = MySignature;
  296.         err = TryDoScript(globals, sourceData, &num);
  297.         if( err == noErr ) { 
  298.             err = AEDuplicateDesc(sourceData, &descCopy);
  299.             if(err == noErr){    
  300.                 err = FindSlotAndPutIt(globals, descCopy, (long *) resultingCompiledScriptID);
  301.             }
  302.         }  
  303.     }
  304.     else{
  305.         err = errOSABadStorageType;
  306.     }    
  307.     return err;
  308. }
  309. //in this sample program, source is same as internal form and  
  310. //there is no special formatting, so just call coerce 
  311. //
  312. pascal ComponentResult DoOSAGetSource(GlobalsHandle globals, OSAID  scriptID,
  313.                             DescType desiredType, AEDesc *resultingSourceData)
  314. {
  315.     return DoOSACoerceToDesc(globals, scriptID, desiredType, 0, resultingSourceData);
  316. }
  317. //
  318. //just store a copy into the slot
  319. //
  320. pascal  ComponentResult DoOSACoerceFromDesc(GlobalsHandle globals, AEDesc *scriptData,
  321.                                  long modeFlags, OSAID *resultingScriptValueID)
  322. {
  323.     
  324.     ComponentResult err;
  325.     AEDesc  descCopy;
  326.  
  327.     err = AEDuplicateDesc(scriptData, &descCopy);
  328.     if( err == noErr ) { 
  329.         *resultingScriptValueID = 0; //put it in a new slot
  330.         err = FindSlotAndPutIt(globals, descCopy, (long *) resultingScriptValueID);
  331.     }
  332.     return err;
  333. }
  334.  
  335. //fetch from the slot and coerce it, if it is source we rename the 
  336. //type because internal form is same as the source text
  337. //
  338. pascal ComponentResult DoOSACoerceToDesc(GlobalsHandle globals, OSAID scriptValueID,
  339.                                DescType  desiredType, long modeFlags, AEDesc *result)
  340. {
  341.     ComponentResult err;
  342.     AEDesc myScriptValue;
  343.  
  344.     if( (scriptValueID <= 0) || (scriptValueID > MaxIDSlot - 1)) { 
  345.         err = errOSAInvalidID;
  346.     }
  347.     else {
  348.         HLock((Handle)globals);
  349.         err = AEDuplicateDesc( &((*globals)->scriptIDSlot[scriptValueID]),&myScriptValue );
  350.         HUnlock((Handle)globals);
  351.         if( err == noErr ){
  352.             if( myScriptValue.descriptorType == MySignature ){  
  353.                 myScriptValue.descriptorType = typeChar; 
  354.             }
  355.             if( myScriptValue.descriptorType == desiredType ) {
  356.                 err = AEDuplicateDesc(&myScriptValue, result);
  357.             }
  358.             else if( desiredType == 'STXT') { 
  359.                 err = TextToStxt(myScriptValue, result);
  360.             }
  361.             else {
  362.                 err = AECoerceDesc(&myScriptValue, desiredType, result);
  363.             }
  364.             AEDisposeDesc(&myScriptValue);
  365.         }
  366.     }
  367.     return err;
  368. }
  369.  
  370. //strip the trailer, execute it and put back the trailer
  371. //there is chance we cannot restore the original form although we are try our best 
  372. //this really calls for a GetScriptDataSize call in OSAComp 
  373. pascal ComponentResult DoOSALoadExecute(GlobalsHandle globals, AEDesc *scriptData,
  374.                               OSAID contextID,  long modeFlags,
  375.                               OSAID *resultingScriptValueID )
  376. {
  377.     ComponentResult  err;
  378.     DescType itsType;
  379.  
  380.     err = errOSABadStorageType;
  381.     if( (*scriptData).descriptorType == kOSAGenericScriptingComponentSubtype ) {
  382.         if( OSAGetStorageType((*scriptData).dataHandle, &itsType) == noErr ) {  
  383.             if( itsType == MySignature ) { 
  384.                 err = OSARemoveStorageType((*scriptData).dataHandle);
  385.                 if( err == noErr ) { 
  386.                     err = DoOSACompileExecute(globals, scriptData, 0, 0, resultingScriptValueID);
  387.                     if( OSAAddStorageType((*scriptData).dataHandle, MySignature) != noErr ) {
  388.                         //we are in deep trouble, we changed scriptData and cannot put it back
  389.                         //dispose result to get back the memory
  390.                         DoOSADispose(globals, *resultingScriptValueID);
  391.                         resultingScriptValueID = 0;
  392.                         //now try again
  393.                         OSAAddStorageType((*scriptData).dataHandle, MySignature);
  394.                         err = memFullErr;  //fail because we don't have enough memory
  395.                     }
  396.                 }
  397.             }
  398.         }
  399.     }
  400.     return err;
  401. }
  402. //
  403. //since source is same as internal form, just execute it and store the result
  404. //
  405. pascal ComponentResult DoOSACompileExecute(GlobalsHandle globals, AEDesc  *sourceData,
  406.                                  OSAID  contextID, long  modeFlags,
  407.                                  OSAID *resultingScriptValueID)
  408. {
  409.     ComponentResult err;
  410.     AEDesc  resultDesc, anoDesc;
  411.  
  412.     err = AEDuplicateDesc(sourceData, &anoDesc);
  413.     if( err == noErr ){
  414.         anoDesc.descriptorType = MySignature;
  415.         err = ActualDoScript(globals, &anoDesc, &resultDesc);
  416.         if( err == noErr ) {  
  417.             err = FindSlotAndPutIt(globals, resultDesc,(long *) resultingScriptValueID); 
  418.         }
  419.         AEDisposeDesc(&anoDesc);
  420.     }
  421.     return err;
  422. }
  423.  
  424. //
  425. //since source is same as internal form, just execute it and return the result
  426. //
  427. pascal ComponentResult DoOSADoScript(GlobalsHandle globals, AEDesc  *sourceData, OSAID  contextID, 
  428.                                     DescType  desiredType, long  modeFlags, AEDesc *resultingText )
  429. {
  430.     ComponentResult   err;
  431.     AEDesc  resultDesc;
  432.  
  433.     (*sourceData).descriptorType = MySignature; 
  434.     NukeIt(resultingText);
  435.     err = ActualDoScript(globals, sourceData, &resultDesc);
  436.     if( err == noErr) { 
  437.         if( (desiredType == resultDesc.descriptorType) || (desiredType == typeWildCard) ){ 
  438.             err = AEDuplicateDesc( &resultDesc, resultingText); 
  439.         }
  440.         else {
  441.             if( desiredType == 'STXT') { 
  442.                 err = TextToStxt(resultDesc, resultingText);
  443.             }
  444.             else {
  445.                 err = AECoerceDesc(&resultDesc, desiredType, resultingText);
  446.                 AEDisposeDesc(&resultDesc);
  447.             }
  448.         }
  449.     }
  450.     return err;
  451. }
  452.  
  453. //
  454. //context is not used in this sample program 
  455. //
  456. pascal ComponentResult DoOSAMakeContext(GlobalsHandle globals, AEDesc  *contextName,
  457.                               OSAID parentContext, OSAID *resultingContextID )
  458. {
  459.     *resultingContextID = 0;
  460.     return noErr;
  461. }
  462.  
  463. //
  464. //return the name of the scripting component
  465. //
  466. pascal OSAError DoOSAScriptingComponentName(GlobalsHandle globals,
  467.                                          AEDesc *resultingScriptingComponentName)
  468. {
  469.     char  aStr[] = "SampleScript";
  470.  
  471.     return AECreateDesc(typeChar, &aStr[0], 12, resultingScriptingComponentName);
  472. }
  473.  
  474. //
  475. //execute the script and return a number or set the error result
  476. //
  477. ComponentResult ActualDoScript(GlobalsHandle globals, AEDesc *scriptData,
  478.                             AEDesc *result)
  479. {
  480.     
  481.     int num;
  482.     OSErr err;
  483.  
  484.     err = TryDoScript(globals, scriptData, &num);
  485.     if( err == noErr) { // THEN 
  486.         err = AECreateDesc(typeShortInteger, &num, sizeof(int), result);
  487.     }
  488.     return err;
  489. }
  490.  
  491. //try to compile the text and return the result 
  492. //we just try to translate one, two, three etc into a number in this simple example  
  493. //
  494. ComponentResult TryDoScript(GlobalsHandle globals, AEDesc *scriptData, int  *num)
  495. {
  496.     char aStr[256] ;
  497.     char  myDigits[10][20] = {"ONE","TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN" };
  498.     OSErr  err;
  499.     int i;
  500.     short myLong;
  501.     char    myComment[256] = "Cannot understand ";
  502.     StringPtr    thePtr;
  503.        
  504.     *num = 0;
  505.     if( (*scriptData).descriptorType == MySignature ) {
  506.         HLock((*scriptData).dataHandle);
  507.         myLong = GetHandleSize((*scriptData).dataHandle);    
  508.         BlockMove(*((*scriptData).dataHandle), &aStr[0],myLong);
  509.         aStr[myLong] = '\0';
  510.         HUnlock((*scriptData).dataHandle);
  511.   
  512.         for(i=0; i < 10; i++){  
  513.             if(myStrcmp(aStr, myDigits[i])){
  514.                 *num = i + 1;
  515.                 break;
  516.             }
  517.         }
  518.         ClearErrorDesc(globals);
  519.         if( *num == 0){
  520.             if(myStrcat(myComment, aStr) == noErr){
  521.                 err = errOSAScriptError;
  522.                 HLock((Handle)globals);
  523.                 (*globals)->errorNumber = err;
  524.                 PtrToXHand( &myComment[0], ((*globals)->errorDesc).dataHandle, myStrlen( myComment)  );
  525.                 HUnlock((Handle)globals);
  526.             }
  527.         }
  528.         else {
  529.             err = noErr;
  530.         }
  531.     }
  532.     else{
  533.         err = errOSABadStorageType;
  534.     }
  535.     return err;
  536. }
  537.  
  538.  
  539. typedef struct  
  540. {
  541.     int scrpNStyles;
  542.     ScrpSTElement  scrpStyle;
  543. }myStyleRec ; 
  544.  
  545.  
  546. //
  547. //convert TEXT to styled text
  548. //
  549. OSErr TextToStxt(AEDesc textDesc, AEDesc *result)
  550. {
  551.     OSErr err;
  552.     AERecord theRec;
  553.     myStyleRec myStyle;
  554.  
  555.     (*result).dataHandle = nil;
  556.     myStyle.scrpNStyles = 1;
  557.     myStyle.scrpStyle.scrpStartChar = 0;
  558.     myStyle.scrpStyle.scrpHeight = 16;
  559.     myStyle.scrpStyle.scrpAscent = 12;
  560.     myStyle.scrpStyle.scrpFont = 1;
  561.     myStyle.scrpStyle.scrpFace = bold; 
  562.     myStyle.scrpStyle.scrpSize = 12;
  563.     myStyle.scrpStyle.scrpColor.red = 0;
  564.     myStyle.scrpStyle.scrpColor.green = 0;
  565.     myStyle.scrpStyle.scrpColor.blue = 0;
  566.  
  567.     err = AECreateList(nil, 0, true, &theRec);
  568.     if( err == noErr){  
  569.         err = AEPutKeyPtr(&theRec, 'ksty', 'styl', &myStyle, sizeof(myStyle));
  570.         if( err == noErr) { 
  571.             err = AEPutKeyDesc(&theRec, 'ktxt', &textDesc);
  572.         }
  573.         if( err == noErr){ 
  574.             err = AECoerceDesc(&theRec, 'STXT', result); 
  575.         }
  576.         AEDisposeDesc(&theRec);
  577.     }
  578.     return err;
  579. }
  580.  
  581. //
  582. //clean up the error message
  583. //
  584. void ClearErrorDesc(GlobalsHandle globals)
  585. {
  586.     HLock((Handle)globals);
  587.     (*globals)->errorNumber = noErr;
  588.     SetHandleSize(((*globals)->errorDesc).dataHandle, 0);
  589.     HUnlock((Handle)globals);
  590. }
  591.  
  592. //
  593. //added this since the documentation says its required 
  594. //returning noErr
  595. pascal ComponentResult DoOSASetScriptInfo(GlobalsHandle globals, OSAID scriptID,
  596.                               OSType selector, long value)
  597. {
  598.     ComponentResult myResult = noErr;
  599.  
  600.     if( selector == kOSAScriptIsModified ){
  601.         myResult = noErr;
  602.     }
  603.     return myResult;
  604.  
  605. }
  606.  
  607. //
  608. //added this since the documentation says its required 
  609. //
  610. pascal ComponentResult DoOSAGetScriptInfo(GlobalsHandle globals,  OSAID scriptID,
  611.                               OSType selector, long * value)
  612. {
  613.     ComponentResult myResult = noErr;
  614.  
  615.     switch ( selector ) {
  616.             
  617.         case kOSAScriptIsModified: 
  618.             *value = 1;
  619.             break;
  620.                 
  621.         case kOSAScriptIsTypeCompiledScript:
  622.             *value = 1;
  623.             break; 
  624.                
  625.         case kOSAScriptIsTypeScriptValue:
  626.             *value = 1;
  627.             break; 
  628.                 
  629.         case kOSAScriptIsTypeScriptContext:
  630.             *value = 1;
  631.             break; 
  632.                 
  633.         case kOSAScriptBestType:
  634.             *value = (long) typeChar;
  635.             break; 
  636.                                 
  637.         case kOSACanGetSource:
  638.             *value = 1;
  639.             break;     
  640.                 
  641.         default :
  642.             myResult = paramErr;
  643.     }
  644.     return myResult;       
  645. }
  646.  
  647. //
  648. //if two strings are the same return 1 otherwise return 0
  649. //make them case independent
  650. //
  651. int myStrcmp( char * firstString, char * secString)
  652. {
  653.     int     i=0;
  654.     short    myShort, aShort;
  655.     
  656.     
  657.     aShort = (short) ('a' - 'A' );
  658.     while( firstString[i] != '\0' ){
  659.         myShort = (short) ( firstString[i] - secString[i] );
  660.         if( ( (myShort % aShort) == 0  )&&(secString[i] != '\0')){
  661.             i++;
  662.         }
  663.         else{
  664.             return 0;
  665.         }
  666.     }
  667.     
  668.     if(secString[i] != '\0')
  669.         return 0;
  670.     else
  671.         return 1;        
  672. }
  673.  
  674. //
  675. //concatenate two strings the second to the first
  676. //
  677. OSErr myStrcat( char * firstString, char * secString)
  678. {
  679.     int i = 0;
  680.     int j = 0;
  681.     OSErr    myErr;
  682.     
  683.     while( (firstString[i] != '\0') && i < 100){
  684.         i++;
  685.     }
  686.     if( i == 100){
  687.         myErr = 1; //some error
  688.         return myErr;
  689.     }
  690.     while( (secString[j] != '\0') && j < 100){
  691.         firstString[i+j] = secString[j];
  692.         j++;
  693.     }
  694.     if( j == 100){
  695.         myErr = 1; //some error
  696.         return myErr;
  697.     }
  698.     firstString[i+j] = '\0';
  699.     return noErr;
  700. }
  701.  
  702. //
  703. // get the string length
  704. //
  705. int myStrlen( char * theString)
  706. {
  707.     int i=0;
  708.     
  709.     while( (theString[i] != '\0') && (i< 200) ){
  710.         i++;
  711.     }
  712.     return i+1;
  713. }
  714.